package com.manpower.configuraion;

import com.manpower.base.AuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@SpringBootConfiguration
public class SpringBootConfiguraion extends WebMvcConfigurationSupport {

	@Autowired
	private AuthInterceptor authInterceptor;

	@Override
	protected void addInterceptors(InterceptorRegistry registry) {

		// 登录凭证验证
		// 身份认证：这里api开头的不用拦截，因为我们定义api开头的为该 系统开放给第三方的接口，我们专门有拦截器做处理
		registry.addInterceptor(authInterceptor).addPathPatterns("/**/api/**");
//				.excludePathPatterns("/login/**")
//				.excludePathPatterns("/api/**")
//				.excludePathPatterns("/**/download/**")
//				.excludePathPatterns("/**/upload/**")
//				.excludePathPatterns("/**/ueditorAction/**");


		// 开放接口认证
//		registry.addInterceptor(apiInterceptor).addPathPatterns("/api/**");


	}

	/**
	 * 发现如果继承了WebMvcConfigurationSupport，则在yml中配置的相关内容会失效。 需要重新指定静态资源
	 *
	 * @param registry
	 */
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/**").addResourceLocations(
				"classpath:/static/");
		registry.addResourceHandler("swagger-ui.html").addResourceLocations(
				"classpath:/META-INF/resources/");
		registry.addResourceHandler("/webjars/**").addResourceLocations(
				"classpath:/META-INF/resources/webjars/");
		super.addResourceHandlers(registry);
	}


}
